package cn.tedu.fy.pethome.service.impl;

import cn.tedu.fy.pethome.ex.ServiceException;
import cn.tedu.fy.pethome.mapper.SkuMapper;
import cn.tedu.fy.pethome.pojo.vo.SkuStandardVO;
import cn.tedu.fy.pethome.service.IForOrderSkuService;
import cn.tedu.fy.pethome.web.ServiceCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ForOrderSkuServiceImpl implements IForOrderSkuService {
    @Autowired
    private SkuMapper skuMapper;
    @Override
    @Transactional
    public int reduceStockNum(Long skuId, Integer quantity) {
        return skuMapper.updateStockById(skuId,quantity);
    }

    @Override
    public SkuStandardVO getById(Long id) {
        SkuStandardVO sku = skuMapper.getById(id);
        if (sku == null) {
            throw new ServiceException(ServiceCode.ERR_NOT_FOUND, "获取SKU详情失败，尝试访问的数据不存在！");
        }
        return sku;
    }
}
